package cn.mashiro.modules.goods.serviceimpl;

import cn.mashiro.common.enums.ResultCode;
import cn.mashiro.common.execption.ServiceException;
import cn.mashiro.common.utils.PageUtil;
import cn.mashiro.modules.goods.entity.dos.Brand;
import cn.mashiro.modules.goods.entity.dto.BrandPageDTO;
import cn.mashiro.modules.goods.mapper.BrandMapper;
import cn.mashiro.modules.goods.service.BrandService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;


@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {

    @Override
    public IPage<Brand> getBrandsByPage(BrandPageDTO page) {
        LambdaQueryWrapper<Brand> wrapper = new LambdaQueryWrapper<>();
        if (!ObjectUtils.isEmpty(page.getBrandName())) {
            wrapper.like(Brand::getBrandName, page.getBrandName());
        }
        return this.page(PageUtil.initPage(page), wrapper);
    }
}
